<template>
	<div>
		<t1 v-model:value="t1"></t1>
		<t2 v-model:value="t2"></t2>
	</div>
	<Row>
		<Button type="default" @click="add">操作</Button>
	</Row>
</template>
<script>
import t1 from './251013_1_1.vue'
import t2 from './251013_1_2.vue'
import { wrap, partial, omit } from 'lodash';
export default {
	name: 'componentDataMerge',
	components: {
		t1,
		t2
	},
	data() {
		return {
			t1: {
				a: 1,
				b: 2
			},
			t2: {
				b: 2,
				c: 3
			}
		}
	},
	methods: {
		add() {
			console.log('t1,t2', this.t1, this.t2);
		}
	},
	mounted() {
		let reg = /\B(?=(\d{3})+(?!\d))/g;
		const number = "1111111111111111";
		const n = number.replace(reg, ',');

		let ms = number.match(reg);
		console.log(ms);
		console.log(n);

		let str = 'dddabcabcabc';
		//第二个c后面插入文字
		reg = /(?<=(abc){2})/;
		ms = str.match(reg);
		let result = str.replace(reg, '【这里是插入的内容】');
		console.log(result);
		console.log('2', ms);
		const n1 = "1111";
		// reg = /(?=(\d{3})+(?!\d))/g
		reg = /(?=(\d{3})+(?!\d))/g
		//reg = /(?<=(\d{3})+(?!\d))/g
		let rr = n1.replace(reg, ',');
		console.log(rr);

		//找到一个代码里面的所有对象，解析出来
		str = `
		{a:1}	000dd {b:2}
		c d{
		a : "1",
		b : 2
		}
		`
		reg = /\{([^}]+)\}/g
		let m1
		let list = []
		while (m1 = reg.exec(str)) {
			let pv = m1[1].replace(/[\t\n\s]/g, '');
			let elems = pv.split(',');
			let obj = {}
			elems.forEach(elem => {
				let [k, v] = elem.split(':');
				obj[k] = JSON.parse(v);
			})
			list.push(obj);
		}
		console.log(list);
		/*
		ms = str.match(reg);
		console.log('objects', ms);
		ms = ms.map(res => {
			return res.replace(/[\t\n\s]/g, '');
		}).forEach(res => {
			console.log(res);
			//let obj = JSON.parse(res);
		})
			*/
		let convert = (num, min = 0, max = 100) => {
			let pnum = parseFloat(num);
			if (isNaN(pnum)) {
				num = 0
			} else {
				num = pnum
				if (num > max) {
					num = max
				} else if (num < min) {
					num = 0;
				}
			}
			return num;
		}


		const f1 = (a) => {
			console.log(a);
			return a + 1;
		}

		const f2 = wrap(f1, function (f1, text) {
			return f1(text + 999);
		});

		f2(1);

		let convert_0_10 = partial(convert, _, 0, 10);
		let c2 = convert_0_10(100);
		console.log(c2);

		// convert = wrap(convert, function (f, num) {
		// 	console.log(`before`, num);
		// 	let n = f(num);
		// 	console.log(`after`, n);
		// });

		//这里使用全局变量问题很大，引用被修改后，内部引用寻找也跟着变化导致无限循环
		// let nc = function (num) {
		// 	console.log(`before`, num);
		// 	let n = convert(num)
		// 	console.log(`after`, n);
		// };
		// nc(101);
		// nc(-1);
		// nc("abc");
		// nc("99");
		// nc(12)
		// nc("24")

		convert(101);
		convert(-1);
		convert("abc");
		convert("99");
		convert(12)
		convert("24")


		let obj = {
			a: 1,
			b: 2
		}
		obj = omit(obj, 'a');
		console.log(obj)
	}
}
</script>
<style lang="scss" scoped></style>